﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using NPSoft.Ferrero.DataBridge.Model;
using NPSoft.Ferrero.Framework.DAL;

namespace NPSoft.Ferrero.DataBridge.DAL
{
    public class ProductRTPriceUtil : IDAL<ProductRTPrice>
    {
        public int Add(ProductRTPrice info)
        {
            throw new NotImplementedException();
        }

        public int Edit(ProductRTPrice info)
        {
            throw new NotImplementedException();
        }

        public ProductRTPrice GetById(long id)
        {
            throw new NotImplementedException();
        }

        public ProductRTPrice GetById(Guid id)
        {
            throw new NotImplementedException();
        }

        public int Remove(ProductRTPrice info)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet Search(StringBuilder condtion)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// SQL连接
        /// </summary>
        private SqlConnection Connection
        {
            get
            {
                return SqlHelper.GetConnection();
            }
        }
        public ICollection<ProductRTPrice> SearchCollection(StringBuilder condtion)
        {
            ICollection<ProductRTPrice> infos = new List<ProductRTPrice>();
            StringBuilder sql = new StringBuilder();
            sql.Append(@"SELECT CMCL_CD,FS_YEAR,CMCL_CN_DESC,BRAND,START_TIME,END_TIME,CHANNEL,CASE ISNULL(PRICE,'') WHEN '' THEN '0.0' ELSE PRICE END PRICE FROM MST_PRD_RTPRC");

            string sWhere = " where ";
            if (!string.IsNullOrEmpty(condtion.ToString()))
            {

                sql.Append(sWhere + condtion);
            }
            DataSet ds;
            ds = SqlHelper.ExecuteDataset(this.Connection, CommandType.Text, sql.ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                infos.Add(SetInfo(row));
            }
            return infos;
        }

        public ProductRTPrice SetInfo(System.Data.DataRow row)
        {
            ProductRTPrice proRTPrice = new ProductRTPrice();
            proRTPrice.BRAND = SqlHelper.GetString(row, "BRAND");
            proRTPrice.CHANNEL = SqlHelper.GetString(row, "CHANNEL");
            proRTPrice.CMCL_CD = SqlHelper.GetString(row, "CMCL_CD");
            proRTPrice.CMCL_CN_DESC = SqlHelper.GetString(row, "CMCL_CN_DESC");
            proRTPrice.END_TIME = SqlHelper.GetDateTime(row, "END_TIME");
            proRTPrice.FS_YEAR = SqlHelper.GetString(row, "FS_YEAR");
            proRTPrice.PRICE = SqlHelper.GetDecimal(row, "PRICE",0);
            proRTPrice.START_TIME = SqlHelper.GetDateTime(row, "START_TIME");

            return proRTPrice; 
        }
    }
}
